using System;
using System.Collections.Generic;
using System.Data;
using PugLib;

namespace ParallelTest
{
    public partial class Benchmarks
    {
        public class RowObject
        {
            public long Aziz;
            public string Boom, Carp, Durp, Eek, Fark, Goon;

            public RowObject(DataRow dr)
            {
                Aziz = (long)dr[0];
                Boom = (string)dr[1];
                Carp = (string)dr[2];
                Durp = (string)dr[3];
                Eek = (string)dr[4];
                Fark = (string)dr[5];
                Goon = (string)dr[6];
            }
        }


        public static TestResult ListSelectFindAll()
        {
            const string name = "ListSelectFindAll";
            Console.WriteLine(name);
            TestResult trd = new TestResult(name);

            DataTable dt = GetTestDataTable(name, false, false, SelectRowCount);
            List<RowObject> lst = new List<RowObject>(SelectRowCount);
            for (int i = 0; i < SelectRowCount; i++)
            {
                lst.Add(new RowObject(dt.Rows[i]));
            }

            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < SelectCount; i++)
            {
                lst.FindAll(delegate(RowObject ro)
                {
                    return ((ro.Aziz == (long)i) && (0 == string.Compare(ro.Boom, i.ToString())));
                });
            }
            stopwatch.Stop();
            dt.Dispose();
            trd.Duration = stopwatch.Elapsed.TotalSeconds;
            return trd;
        }

        public static TestResult ListSelectFind()
        {
            const string name = "ListSelectFind";
            Console.WriteLine(name);
            TestResult trd = new TestResult(name);

            DataTable dt = GetTestDataTable(name, false, false, SelectRowCount);
            List<RowObject> lst = new List<RowObject>(SelectRowCount);
            for (int i = 0; i < SelectRowCount; i++)
            {
                lst.Add(new RowObject(dt.Rows[i]));
            }

            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < SelectCount; i++)
            {
                lst.Find(delegate(RowObject ro)
                 {
                     return ((ro.Aziz == (long)i) && (0 == string.Compare(ro.Boom, i.ToString())));
                 });
            }
            stopwatch.Stop();
            dt.Dispose();
            trd.Duration = stopwatch.Elapsed.TotalSeconds;
            return trd;
        }

    }
}
